﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Linq;
namespace Exact_Extension
{
    public partial class MsgUpdateDueDate : DevExpress.XtraEditors.XtraForm
    {
        ExactDataContext DS;
        List<ISHCMC_Invoice> InvoiceDetail;
        public MsgUpdateDueDate(ExactDataContext _DS, List<ISHCMC_Invoice> _InvoiceDetail)
        {
            InitializeComponent();
            InvoiceDetail = _InvoiceDetail;
            DS = _DS;
            this.dateEdit_DueDate.EditValue = DateTime.Now.Date;

        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
  
                try
                {
 
                    foreach (ISHCMC_Invoice itemInvDetail in InvoiceDetail)
                    {
                        ISHCMC_Invoice InvDetailUpdate = DS.ISHCMC_Invoices.Single(c => c.ID == itemInvDetail.ID);
                        InvDetailUpdate.DueDate = Convert.ToDateTime(this.dateEdit_DueDate.EditValue);
                        
                    }
                    DS.SubmitChanges();
                    this.DialogResult = DialogResult.Yes;
                }
                catch (Exception ex)
                {
                    this.DialogResult = DialogResult.No;
                }
           
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}